package com.james.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.james.domain.User;
import com.james.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @ClassName: UserDetailsServiceImpl
 * @Author: JamesWang
 * @Date: 2021/4/18 19:39
 * @Description:
 * @Version:1.0
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    UserService userService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        return userService.getOne(new QueryWrapper<User>()
                .eq(StringUtils.hasText(username), User.COL_USER_NAME, username)
        );
    }

}
